/**
 * @FILENAME:  typing.ts
 *  @Description:  // 存放跟table相关的属性
 * @Author: ellwood
 * @CreateDate: 2024/11/6 - 11:57
 * @Version: V1.0.0
 */
import type { DataTableColumn } from 'naive-ui'
import { dataTableProps } from 'naive-ui'
import type { VNodeChild } from 'vue'
import type { ExtractPropTypes, PropType } from '@vue/runtime-core'

/**
 * 定义value的枚举
 */
export interface ProTableValueEnum {
  label: string | (() => VNodeChild)
  value: string | number
}

/**
 * 继承DataTableColumn并将需要扩展的属性再写进去
 */
export type ProTableColumn = DataTableColumn & {
  valueType?: 'input' | 'select'
  valueEnum?: Record<string, ProTableValueEnum>
  key?: string
  title?: string
}

export interface ProTableOptions {
  reload?: boolean
  setting?: boolean
}

export interface ProTableRequestCallback {
  data: Record<string, any>
  total: number
}

export type ProTableRequest = (
  params?: Record<string, any>,
) => Promise<ProTableRequestCallback>

export const proTableProps = {
  ...dataTableProps,
  columns: {
    type: Array as PropType<ProTableColumn[]>,
    default: () => [],
  },
  options: {
    type: [Object, Boolean] as PropType<false | ProTableOptions>,
    default: () => ({ reload: true, setting: true }),
  },
  request: {
    type: Function as PropType<ProTableRequest>,
    default: undefined,
  },
}

export type ProTableProps = ExtractPropTypes<typeof proTableProps>
